package GUILayer;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

public class MainGUI extends JFrame {

	private JFrame frmHovedMenu;
	private static LoginGUI loginGUI;
	private static String loginName;
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainGUI window = new MainGUI(loginName, loginGUI);
					window.frmHovedMenu.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public MainGUI(String loginName, LoginGUI logOn) {
		initialize();
		//loginGUI = logOn;
		//personCtr = new PersonCtr();
		frmHovedMenu.setVisible(true);
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmHovedMenu = new JFrame();
		frmHovedMenu.setTitle("Hoved menu");
		frmHovedMenu.setBounds(100, 100, 450, 353);
		frmHovedMenu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JButton salesMenuButton = new JButton("Salgs menu");
		salesMenuButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				enterSalesMenu();
			}
		});
		
		JButton personMenuButton = new JButton("Person menu");
		personMenuButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			new PersonGUI();
			}
		});
		
		JButton vareMenuButton = new JButton("Vare menu");
		vareMenuButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			new ItemGUI();
			}
		});
		
		JButton logOutButton = new JButton("Log ud");
		logOutButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				logOut();
			}
		});
		GroupLayout groupLayout = new GroupLayout(frmHovedMenu.getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(154)
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addComponent(logOutButton, GroupLayout.PREFERRED_SIZE, 159, GroupLayout.PREFERRED_SIZE)
						.addComponent(vareMenuButton, GroupLayout.PREFERRED_SIZE, 159, GroupLayout.PREFERRED_SIZE)
						.addComponent(personMenuButton, GroupLayout.PREFERRED_SIZE, 159, GroupLayout.PREFERRED_SIZE)
						.addComponent(salesMenuButton, GroupLayout.PREFERRED_SIZE, 159, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(137, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(6)
					.addComponent(salesMenuButton, GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(personMenuButton, GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(vareMenuButton, GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(logOutButton, GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(69, Short.MAX_VALUE))
		);
		frmHovedMenu.getContentPane().setLayout(groupLayout);
		
		JMenuBar menuBar = new JMenuBar();
		frmHovedMenu.setJMenuBar(menuBar);
		
		JMenu mnNewMenu = new JMenu("Filer");
		menuBar.add(mnNewMenu);
		
		JMenuItem mntmAfslutProgram = new JMenuItem("Afslut program");
		mntmAfslutProgram.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		mnNewMenu.add(mntmAfslutProgram);
		
		JMenu mnNewMenu_1 = new JMenu("Hj\u00E6lp");
		menuBar.add(mnNewMenu_1);
		
		JMenuItem mntmOm = new JMenuItem("Om");
		mntmOm.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				showAbout();
			}
		});
		mnNewMenu_1.add(mntmOm);
		
		frmHovedMenu.setVisible(true);
	}
	
	private void logOut()
	{
		new LoginGUI();
		frmHovedMenu.dispose();
	}
	
	private void enterSalesMenu()
	{
			System.out.println("OK");
			new SalesGUI();
            //salesGUI.frame.setVisible(true);
            this.setVisible(false);
	}
	
	private void showAbout()
	{
		JOptionPane.showMessageDialog(frmHovedMenu, "Vestbjerg Byggecenter\n" + "Version 1.0", "About Vestbjerg Byggecenter", JOptionPane.INFORMATION_MESSAGE);
	}
	
	private static final long serialVersionUID = 7526472295622776147L;
}
